package com.example.qxfw.mongodb.hy.service.impl;

import com.example.qxfw.mongodb.hy.entity.HyAridWarnAnalysisFile;
import com.example.qxfw.mongodb.hy.service.GridWarnAnalysisFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service
public class GridWarnAnalysisFileServiceImpl implements GridWarnAnalysisFileService {

    @Qualifier("mongoSecondTemplate")
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public HyAridWarnAnalysisFile getByTableId(String tableId) {
        Query query = new Query(Criteria.where("table_id").is(tableId));
        return mongoTemplate.findOne(query, HyAridWarnAnalysisFile.class);
    }

    @Override
    public Boolean isExist(String tableId) {
        Query query = new Query(Criteria.where("table_id").is(tableId));
        return mongoTemplate.exists(query, HyAridWarnAnalysisFile.class);
    }

    @Override
    public HyAridWarnAnalysisFile deleteByTableId(String tableId) {
        Query query = new Query(Criteria.where("table_id").is(tableId));
        return mongoTemplate.findAndRemove(query,HyAridWarnAnalysisFile.class);
    }


}
